package cn.jhc.servlet;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.jhc.bean.HfmsgBean;
import cn.jhc.bean.UserBean;
import cn.jhc.dao.ConnectionFactory;
import cn.jhc.dao.ShowmvDAO;

@WebServlet(name = "Get uploadMV HF detail", urlPatterns = { "/addmvmessage.do" })
public class AddUploadMVMsgServlet extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		UserBean user = (UserBean) req.getSession().getAttribute("user");
		if (null == user) {
			String getb = (String) req.getParameter("getb");
			String id = (String) req.getParameter("id");
			req.setAttribute("id", id);
			req.setAttribute("getb", getb);
			RequestDispatcher dispatcher = req
					.getRequestDispatcher("/login.jsp");
			dispatcher.forward(req, resp);
			return;
		}
		req.setCharacterEncoding("UTF-8");
		String getb = (String) req.getParameter("getb");
		String content = (String) req.getParameter("content");
		String Uploadmv_id = (String) req.getParameter("uploadmv_id");
		int uploadmv_id = Integer.parseInt(Uploadmv_id);
		int userid = user.getId();
		ShowmvDAO dao = new ShowmvDAO();
		dao.setCon(ConnectionFactory.getConnection());
		dao.addHfMessage(userid, content, uploadmv_id);
		RequestDispatcher dispatcher = req
				.getRequestDispatcher(getb);
		dispatcher.forward(req, resp);
	}
}